﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="WorkFlow_OrgMapping_EmployeeSelect" Codebehind="EmployeeSelect.aspx.cs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>组织机构选择</title>
    <base target="_self" />
       <meta http-equiv="Pragma" content="no-cache" />
       <meta http-equiv="Cache-Control" content="no-cache"/>
       <meta http-equiv="Expires" content="0"/> 
          <script type="text/javascript" src="../Scripts/jquery-1.6.min.js"></script>
    <script language="javascript" type="text/javascript" src="../Scripts/jquery.easyui.min.js"></script>
    <link href="../Styles/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../css/tab/tab.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript" src="../css/tab/tab.js"></script>
    <link href="../Styles/control.css" rel="stylesheet" type="text/css" />
   <script language="javascript" type="text/javascript" >
       $(function () {
           $('#treeOrg').tree({
               checkbox: false,
               dnd: false,
               url: '<%=Page.ResolveClientUrl("~/") %>Workflow/OrgMapping/OrgMapping.ashx?type=1&randID=' + escape(new Date()),
               method: "POST",
               onClick: function (node) {
                   $('#treeOrg').tree('expand', node.target);
                   $("#wait").css("display", "block");
                   $.ajax({
                       type: "POST",
                       cache: true,
                       url: '<%=Page.ResolveClientUrl("~/") %>Workflow/OrgMapping/OrgMapping.ashx?type=2&ID=' + node.id + '&randID=' + escape(new Date()),
                       success: function (msg) {
                           var obj = document.getElementById('<%=SelectEmployee1.ClientID %>');
                           ClearItem(obj);
                           if (msg != "") {
                               var json = eval("(" + msg + ")");
                               for (var i = 0; i < json.length; i++) {
                                   AddItem(obj, json[i].text, json[i].id);
                               }
                           }
                           $("#wait").css("display", "none");
                       },
                       error: function () { $("#wait").css("display", "none"); alert('服务器出错,无法获取数据！'); }
                   });
               }
           });
       });
       function ClearItem(obj) {
           obj.options.length = 0;
       }
       function AddItem(obj, Name, Value) {
           obj.add(document.createElement("OPTION"));
           var len = obj.options.length;
           obj.options[len - 1].text = Name;
           obj.options[len - 1].value = Value;
       }
       </script>
</head>
<body   onload="IniSelect()" style="margin:5px">
    <form id="form1" runat="server">    
       <div id="myTab_l_Content0" >
            <div style="float:left;width:52%;height:370px;border:1px solid #BABABA;overflow:scroll;">
                   <ul id="treeOrg" style="margin:5px;"></ul>
            </div>
            <div style="float:right;width:45%">
                <table border="0" width="100%">
                    <tr>
                        <td align="center">  
                            <asp:ListBox ID="SelectEmployee1"  runat="server" Width=200 Height=160  SelectionMode=Multiple ondblclick="Select('Employee');" >
                                    </asp:ListBox>
                        </td>
                    </tr>
                <tr>
                    <td align=center >
                        <input name="btnselectAction" id="btnselectAction" onclick="javascript:Select('Employee');" class="btn_normal" onmouseover="this.className='btn_active'" onmouseout="this.className='btn_normal'"  type=button  value="选择"/>
                        <input name="btnUnSelectAction" id="btnUnSelectAction" onclick="javascript:UnSelect('Employee');"  class="btn_normal" onmouseover="this.className='btn_active'" onmouseout="this.className='btn_normal'" type=button  value="删除"/> <br /><div style="height:2px;"></div>
                        <input name="btnSelectALL" id="btnSelectALL" onclick="javascript:SelectALL('Employee');"  type=button value="全选"class="btn_normal" onmouseover="this.className='btn_active'" onmouseout="this.className='btn_normal'"  />
                        <input name="btnUnSelectALL" id="btnUnSelectALL" onclick="javascript:UnSelectALL('Employee');" class="btn_normal" onmouseover="this.className='btn_active'" onmouseout="this.className='btn_normal'"  type="button" value="全删" /><div style="height:2px;"></div>
                    </td>
                </tr>
                <tr>
                    <td align="center">  
                        <asp:ListBox ID="SelectEmployee2" runat="server" Width=200 Height=160  SelectionMode=Multiple>
                        </asp:ListBox>
                    </td>
                </tr>
            </table>
            </div>

        </div>
        
<table width="96%" cellpadding="5">
    <tr>
        <td style="text-align:center">
            <asp:Button ID="btnSave" Text = "确定" runat="server"  OnClientClick="GetReturn();return false;" class="btn_normal" onmouseover="this.className='btn_active'" onmouseout="this.className='btn_normal'"  />
        <asp:Button ID="btnExit" Text = "退出" runat="server" OnClientClick="window.close();" class="btn_normal" onmouseover="this.className='btn_active'" onmouseout="this.className='btn_normal'"  />
        </td>
    </tr>
 </table>  
  <div id="wait" style="display:none;width:200px;height:50px;border:1px solid #BABABA;position:absolute;top:50px;left:360px;padding:0px;">
  <img src="../Images/loading.gif" alt='' />数据正在加载中，请稍候……
</div>
 </form>
 <script language ="javascript" type="text/javascript">
     function Select(type) {
         var ctrlName = "SelectEmployee1";
         for (var i = 0; i < document.getElementById(ctrlName).options.length; i++) {
             if (document.getElementById(ctrlName).options[i].selected) {
                 AddNoIn(document.getElementById(ctrlName).options[i].text, document.getElementById(ctrlName).options[i].value, type);
             }
         }
     }
     function UnSelect(type) {
         var ctrlName = "SelectEmployee2";
         for (var i = document.getElementById(ctrlName).options.length - 1; i >= 0; i--) {
             if (document.getElementById(ctrlName).options[i].selected) {
                 document.getElementById(ctrlName).options.remove(i);
             }
         }
     }
     function SelectALL(type) {
         var ctrlName = "SelectEmployee1";
         for (var i = 0; i < document.getElementById(ctrlName).options.length; i++) {
             AddNoIn(document.getElementById(ctrlName).options[i].text, document.getElementById(ctrlName).options[i].value, type);
         }
     }
     function UnSelectALL(type) {
         var ctrlName = "SelectEmployee2";
         document.getElementById(ctrlName).options.length = 0;
     }
     function AddNoIn(Name, Value, type) {
         var ctrlName = "SelectEmployee2";
         if ('<%=Request["mode"]+"" %>' == '1') {
             var arrSelected = GetSelected();
             if (arrSelected != null && arrSelected.length == 1) {
                 alert("只能选择一个人员！");
                 return;
             }
         }
         if (!optionExists(document.getElementById(ctrlName), Value)) {
             document.getElementById(ctrlName).add(document.createElement("OPTION"));
             document.getElementById(ctrlName).options[document.getElementById(ctrlName).options.length - 1].text = Name;
             document.getElementById(ctrlName).options[document.getElementById(ctrlName).options.length - 1].value = Value;
         }
     }
     //检查obj列表框中是否已经存在选项opt
     function optionExists(obj, value) {
         var length = obj.options.length;
         for (var i = 0; i < length; i++) {
             if (obj.options[i].value == value) //如果一个选项的值和文本与给定的选项相同，则表明存在。   
                 return true;
         }
         return false; //不存在   
     }
     function OrgData() {
         var Type;
         var ID;
         var Name;
     }
     function GetSelected() {
         var lsb = document.getElementById("SelectEmployee2");
         if (lsb.options.length == 0) {
             return null;
         }
         var arrSelected = new Array(lsb.options.length);
         var item = null;
         for (var i = 0; i < lsb.options.length; i++) {
             item = new OrgData();
             item.Type = "Employee";
             item.ID = lsb.options[i].value;
             item.Name = lsb.options[i].text;
             arrSelected[i] = item;
         }
         return arrSelected;
     }
     function GetReturn() {
         window.parent.returnValue = GetSelected();
         window.parent.close();
     }
     function GetTypeArr() {
         var typeArr = new Array(3);
         typeArr[0] = "Employee";
         typeArr[1] = "Role";
         typeArr[2] = "Position";
         return typeArr;
     }
     function IniSelect() {
         var cvalue = window.parent.window.dialogArguments;
         if (cvalue != null) {
             var opt = document.getElementById("SelectEmployee2");
             for (var i = 0; i < cvalue.length; i++) {
                 if (cvalue[i].ID != null && (cvalue[i].ID + "") != "") {
                     if (!optionExists(opt, cvalue[i].ID + "")) {
                         opt.add(document.createElement("OPTION"));
                         opt.options[opt.length - 1].text = cvalue[i].Name;
                         opt.options[opt.length - 1].value = cvalue[i].ID;
                     }
                 }
             }
         }
     }
    </script> 
    
</body>
</html>